#ifndef AVCODECSAMPLE_OPENGL_PLUGIN_RENDER_H
#define AVCODECSAMPLE_OPENGL_PLUGIN_RENDER_H

#include <ace/xcomponent/native_interface_xcomponent.h>
#include <napi/native_api.h>
#include <string>
#include <sys/stat.h>
#include <unordered_map>
#include <uv.h>
#include <cstdint>
#include <hilog/log.h>
#include <js_native_api.h>
#include <js_native_api_types.h>
#include "camera.h"
#include "render_thread.h"
#include "common/sample_info.h"

namespace NativeXcomponentSample {
class PluginRender {
public:
    explicit PluginRender(std::string& id);
    ~PluginRender()
    {
        Release(id_);
    }
    static PluginRender* GetInstance(std::string& id);
    static void Release(std::string& id);
    static napi_value StartCamera(napi_env env, napi_callback_info info);
    static napi_value StopCamera(napi_env env, napi_callback_info info);
    static napi_value InitRecorder(napi_env env, napi_callback_info info);
    static napi_value StartRecord(napi_env env, napi_callback_info info);
    static napi_value StopRecord(napi_env env, napi_callback_info info);
    static napi_value InitPlayer(napi_env env, napi_callback_info info);
    static napi_value StartPlay(napi_env env, napi_callback_info info);
    static napi_value StopPlay(napi_env env, napi_callback_info info);
    static napi_value PausePlay(napi_env env, napi_callback_info info);
    static napi_value ResumePlay(napi_env env, napi_callback_info info);
    static napi_value LoopPlay(napi_env env, napi_callback_info info);
    static napi_value Seek(napi_env env, napi_callback_info info);
    static napi_value AddBW(napi_env env, napi_callback_info info);
    void Export(napi_env env, napi_value exports);
    void OnSurfaceChanged(OH_NativeXComponent* component, void* window);
    void OnTouchEvent(OH_NativeXComponent* component, void* window);
    void RegisterCallback(OH_NativeXComponent* nativeXComponent);
    void UpdateNativeWindow(void *window, uint64_t width, uint64_t height);
public:
    static std::unordered_map<std::string, PluginRender *> instance_;
    std::string id_;
    static int32_t hasDraw_;
    static int32_t hasChangeColor_;
private:
    void UpdateNativeWindowSize(uint64_t width, uint64_t height);
    void CreateEncoderSurface(OHNativeWindow *nativeWindow, int32_t videoWidth, int32_t videoHeight);
    void DeleteEncoderSurface();
    void CreateCamera();
    void StopCamera();
    void StopPlay();
    void AddBW();
    
    static PluginRender *GetPluginRender(napi_env env, napi_callback_info info);
//     void Play(SampleInfo &sampleInfo);
private: 
    OH_NativeXComponent_Callback renderCallback_;
    OH_NativeXComponent_MouseEvent_Callback mouseCallback_;
    std::unique_ptr<RenderThread> renderThread_;
    std::unique_ptr<OHOS_CAMERA_SAMPLE::NDKCamera> ndkCamera_;
};
} // namespace NativeXComponentSample

#endif //AVCODECSAMPLE_OPENGL_PLUGIN_RENDER_H
